package com.foreknow.springboot_demo.mapper;

import com.foreknow.springboot_demo.po.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {

    /**
     * 根据用户编号查询此用户所有购物车信息
     * 根据用户编号和商家编号，查询此用户购物车中某个商家的所有购物车信息
     * @param userId,businessId
     * @return
     */
    public List<Cart> listCart(@Param("userId") String userId,@Param("businessId") Integer businessId);

    /**
     * 向购物车表中添加一条记录
     * @param userId
     * @param foodId
     * @param businessId
     * @return
     */
    @Insert("insert into cart(userId, foodId, businessId,quantity) values (#{userId}, #{foodId}, #{businessId},1)")
    public Integer saveCart(@Param("userId") String userId,@Param("foodId") int foodId,@Param("businessId") int businessId);


    /**
     *根据用户编号、商家编号、食品编号更新数量
     * @param userId
     * @param foodId
     * @param businessId
     * @param quantity
     * @return
     */
    @Update("update cart set quantity = #{quantity} where userId = #{userId} and foodId = #{foodId} and businessId = #{businessId}")
    public Integer updateCart(@Param("userId") String userId,@Param("foodId") int foodId,@Param("businessId") int businessId,@Param("quantity") int quantity);

    /**
     * 根据用户编号、商家编号、食品编号删除购物车表中的一条食品记录
     * 根据用户编号、商家编号删除购物车表中的多条条记录
     * @param userId
     * @param foodId
     * @param businessId
     * @return
     */
    public Integer removeCart(@Param("userId") String userId,@Param("foodId") Integer foodId,@Param("businessId") Integer businessId);
}
